﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DoAnB
{
    public partial class frmThanhToan : Form
    {
        double tien = Main.tien;
        public frmThanhToan()
        {
            InitializeComponent();
            labelBanThanhtoan.Text = Main.banguitoisubform + " - " + tien.ToString("###,###,###");
        }

        private void textBoxGiamGia_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
            {
                e.Handled = true;
            }
            if (e.KeyChar == '.'
                && (sender as TextBox).Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }
        }

        private void textBoxPhiPhucVu_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
            {
                e.Handled = true;
            }
            if (e.KeyChar == '.'
                && (sender as TextBox).Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double giamgia = 0 + double.Parse(textBoxGiamGia.Text);
            double phucvu = 0 + double.Parse(textBoxPhiPhucVu.Text) * 1000;
            if (giamgia > 100)
                MessageBox.Show("Giảm giá quá quy định", "Thông báo", MessageBoxButtons.OK);
            else
            {
                double tongcong = (tien + phucvu) / 100 * (100 - giamgia);
                lblTongCongXXX.Text = tongcong.ToString("###,###,###");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void textBoxGiamGia_Leave(object sender, EventArgs e)
        {
            double giamgia = 0 + double.Parse(textBoxGiamGia.Text);
            double phucvu = 0 + double.Parse(textBoxPhiPhucVu.Text) * 1000;
            if (giamgia > 100)
                MessageBox.Show("Giảm giá quá quy định", "Thông báo", MessageBoxButtons.OK);
            else
            {
                double tongcong = (tien + phucvu) / 100 * (100 - giamgia);
                lblTongCongXXX.Text = tongcong.ToString("###,###,###");
            }
        }

        private void textBoxPhiPhucVu_Leave(object sender, EventArgs e)
        {
            double giamgia = 0 + double.Parse(textBoxGiamGia.Text);
            double phucvu = 0 + double.Parse(textBoxPhiPhucVu.Text) * 1000;
            if (giamgia > 100)
                MessageBox.Show("Giảm giá quá quy định", "Thông báo", MessageBoxButtons.OK);
            else
            {
                double tongcong = (tien + phucvu) / 100 * (100 - giamgia);
                lblTongCongXXX.Text = tongcong.ToString("###,###,###");
            }
        }





    }
}
